package com.ptr.controladores;

/**
 *
 * @author MVR
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import com.ptr.controladores.driversql;

public class conexionsqlserver {

    public Connection con = null;
    driversql dsql=new driversql();
    public conexionsqlserver() {
    }
    public void conectar() throws SQLException
    {
        
        try {
            Class.forName(dsql.driver());
               String url = "jdbc:sqlserver:"+dsql.lhost()+
                       ";databaseName="+dsql.bd()+
                       ";user="+dsql.us()+
                       ";password="+dsql.pw()+";";
               con=DriverManager.getConnection(url);
             }
            catch (SQLException e) {
                System.out.println("SQL Exception: "+ e.toString());
             } catch (ClassNotFoundException cE) {
                    System.out.println("Class Not Found Exception: "+ cE.toString());
               }
    }
    public void cerrarBD()
    {
        if(con !=null)
        {try
            {   con.close();
                System.out.println("Cerrando la conexion"+dsql.server);
            }   catch(SQLException ex)
            {System.out.println("Error en cerrar la conexion"+ex.getMessage());}
        }
    }
    public Connection getconection()
    {return con;}
}
